import smtplib
import sys

if len(sys.argv) < 2:   
	print 'Wrong parameter.'  
	sys.exit()

caseName = sys.argv[1]
level = sys.argv[2]

print caseName
print level


FROMADDR = "mape2emonitoring_SVC_BE@nokia.com"
if level == 'ResultNotFound':
	TOADDRS  = ['duan.y@neusoft.com','ext-candy.1.tang@nokia.com','516873654@qq.com']
	##TOADDRS  = ['jiaodaa@qq.com']
else:
	TOADDRS  = ['I_EXT_LOCN_SYSENG_CN@nokia.com', 'duan.y@neusoft.com','ext-candy.1.tang@nokia.com','516873654@qq.com']
	
##TOADDRS  = ['jiaodaa@qq.com']
SUBJECT  = "MAPS SR6 Alert: " + caseName + " " + level

msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
       % (FROMADDR, ";".join(TOADDRS), SUBJECT) )
msg += "MAPS SR6 Alert fired: " + caseName + " " + level + ".\r\n"
msg += "Introduction: .\r\n"
msg += "Alert marks one case failed: .\r\n"
msg += "P3 means this case failed once in the past 10 test asserts.\r\n"
msg += "P2 means this case failed 2 or 3 times in the past 10 test asserts.\r\n"
msg += "P1 means this case failed more than 3 times in the past 10 test asserts.\r\n"
msg += "Alert marks test assert failed: .\r\n"
msg += "P3 means the last case skipped once in the past 10 test asserts.\r\n"
msg += "P2 means the last case consecutive skipped 2 times in the past 10 test asserts.\r\n"
msg += "P1 means the last case consecutive skipped more than 2 times in the past 10 test asserts.\r\n"
msg += "Alert marks test result not found: .\r\n"
msg += "No test result found in 30 min.\r\n"

server = smtplib.SMTP('smtp.nokia.com', 25)
server.set_debuglevel(1)
server.ehlo()
##server.starttls()
##server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
